﻿using UnityEngine;
using System;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;

[Constructable]
public class BattleStation : Building, IConstructable
{
	private double m_TurnCounter;				// for IConstructable

	#region IConstructable
	public double TurnCounter
	{
		get { return m_TurnCounter; }
		set { m_TurnCounter = value; }
	}
	#endregion

	public BattleStation()
	{
		this.Name = GameEnums.Facilities.BattleStation;
		this.DispName = Utility.SplitName(this.Name.ToString());
		this.MotherTech = new GameEnums.TechName[] { GameEnums.TechName.BattleStation };
		this.Obsolete = new GameEnums.Facilities[] { GameEnums.Facilities.StarBase };
	}
	
	public BattleStation(bool getID) : this()
	{
		FacilityID = ++Galaxy.FacilitySerial;
		Core.Buildings.Add(FacilityID, this);
	}

	public BattleStation(Planet pl)
	{
		Planet = pl;
	}

	public override void OnTurn()
	{
		base.OnTurn();

		Planet.Kingdom.Gold -= 3;
	}

	public override void OnTurn(Planet pl)
	{
		base.OnTurn(pl);

		Planet = pl;
		this.OnTurn();
	}

	public override void OnBuilt()
	{
		base.OnBuilt();

		Planet.BaseDefense += 16;
		Planet.Kingdom.Command += 3;

		// to remove the effect of Star Base
		foreach (Planet.PlanetFacility pf in Planet.Facilities)
			if (pf.pBuild.Name == GameEnums.Facilities.StarBase)
				pf.pObsolete = true;

		Planet.HugeShip = true;			// reset flag after removing starbase, can produce large ships
	}

	public override void OnBuilt(Planet pl)
	{
		base.OnBuilt(pl);

		Planet = pl;
		this.OnBuilt();
	}

	public override void OnRemove()
	{
		base.OnRemove();

		Planet.BaseDefense -= 16;
		Planet.HugeShip = false;
		Planet.Kingdom.Command -= 3;

		Building.OnRemove(Planet, this);
	}

}